Added xsls utility, which recursively lists the contents of the store.
authoremellor@ewan <emellor@ewan>
Tue, 11 Oct 2005 09:29:29 +0000 (10:29 +0100)
committeremellor@ewan <emellor@ewan>
Tue, 11 Oct 2005 09:29:29 +0000 (10:29 +0100)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
.hgignore
tools/xenstore/Makefile
tools/xenstore/xsls.c [new file with mode: 0644]

index 72b8f826d783c8b6fb55b339c0904e194039e78d..a4e2a8ee32abaeffcd428a6e24f8f9e252a73d6e 100644 (file)
--- a/.hgignore
+++ b/.hgignore
 ^tools/xenstore/xs_tdb_dump$
 ^tools/xenstore/xs_test$
 ^tools/xenstore/xs_watch_stress$
+^tools/xenstore/xsls$
 ^tools/xentrace/xenctx$
 ^tools/xentrace/xentrace$
 ^xen/BLOG$
index 212ae13e4aa60e8358ac716a6d35b4d02eae34da..5d29ad301a69a53623c8817f77e92c39bcb276d9 100644 (file)
@@ -27,7 +27,7 @@ CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm
 CLIENTS += xenstore-write
 CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS))
 
-all: libxenstore.so xenstored $(CLIENTS) xs_tdb_dump
+all: libxenstore.so xenstored $(CLIENTS) xs_tdb_dump xsls
 
 testcode: xs_test xenstored_test xs_random
 
@@ -40,6 +40,9 @@ $(CLIENTS): xenstore-%: xenstore_%.o
 $(CLIENTS_OBJS): xenstore_%.o: xenstore_client.c
        $(COMPILE.c) -DCLIENT_$(*F) -o $@ $<
 
+xsls: xsls.o
+       $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -L. -lxenstore -o $@
+
 xenstored_test: xenstored_core_test.o xenstored_watch_test.o xenstored_domain_test.o xenstored_transaction_test.o xs_lib.o talloc_test.o fake_libxc.o utils.o tdb.o
        $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
 
@@ -134,6 +137,7 @@ install: libxenstore.so xenstored $(CLIENTS)
        $(INSTALL_DIR) -p $(DESTDIR)/usr/include
        $(INSTALL_PROG) xenstored $(DESTDIR)/usr/sbin
        $(INSTALL_PROG) $(CLIENTS) $(DESTDIR)/usr/bin
+       $(INSTALL_PROG) xsls $(DESTDIR)/usr/bin
        $(INSTALL_DIR) -p $(DESTDIR)/usr/$(LIBDIR)
        $(INSTALL_DATA) libxenstore.so $(DESTDIR)/usr/$(LIBDIR)
        $(INSTALL_DATA) xs.h $(DESTDIR)/usr/include
diff --git a/tools/xenstore/xsls.c b/tools/xenstore/xsls.c
new file mode 100644 (file)
index 0000000..f8cf245
--- /dev/null
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <err.h>
+#include <xs.h>
+
+void print_dir(struct xs_handle *h, char *path, int cur_depth)
+{
+    char **e;
+    char newpath[512], *val;
+    int num, i, len;
+
+    e = xs_directory(h, NULL, path, &num);
+    if (e == NULL)
+        err(1, "xs_directory (%s)", path);
+
+    for (i = 0; i<num; i++) {
+        int j;
+        for (j=0; j<cur_depth; j++) printf(" ");
+        printf("%s", e[i]);
+        sprintf(newpath, "%s%s%s", path, 
+                path[strlen(path)-1] == '/' ? "" : "/", 
+                e[i]);
+        val = xs_read(h, NULL, newpath, &len);
+        if (val == NULL)
+            printf(":\n");
+        else if ((unsigned)len > (151 - strlen(e[i])))
+            printf(" = \"%.*s...\"\n", 148 - strlen(e[i]), val);
+        else
+            printf(" = \"%s\"\n", val);
+        free(val);
+        print_dir(h, newpath, cur_depth+1); 
+    }
+    free(e);
+}
+
+int main(int argc, char *argv[])
+{
+    struct xs_handle *xsh = xs_daemon_open();
+
+    if (xsh == NULL)
+        err(1, "xs_daemon_open");
+
+    print_dir(xsh, argc == 1 ? "/" : argv[1], 0);
+
+    return 0;
+}